<?php
/* 
* @Author: LDF QQ 47121862
* @Date:   2014-05-29 09:06:25
* @Last Modified by:   LDF QQ 47121862
* @Last Modified time: 2014-06-12 17:41:28
*/
Class UserControl extends ConfigControl{
	Public $model;
	Public function __auto(){
		$this->model=K('User');
	}
	//用户中心
	function index(){
		if(!$_SESSION['user']['uid']) go('Index/index');
		// p($_SERVER);
		$user=M('user')->where(array('uid'=>$_SESSION['user']['uid']))->find();
		// p($user);

		$this->user=$user;
		$this->display();
	}
	//验证密码
	function checkUser(){
		
	}
	//登陆
	Public function login(){
		if(IS_AJAX){ //ajax提交
			if($this->model->login()){
				echo 1;die;
			}else{
				echo 0;die;
			}
		}
		if(IS_POST){
			if($this->model->login()){
				$this->success('登陆成功',U('Index/index'));
			}else{
				$this->error($this->model->error);
			}
		}else{
			$this->display();
		}
	}
	//注册
	Public function reg(){
		if(IS_POST){
			if($this->model->reg()){
				$this->success('用户注册成功',U('Index/index'));
			}else{
				$this->error($this->model->error);
			}
		}else{
			$this->display();
		}
	}
	//验证码
	Public function code(){
		$code = new Code();
		$code->show();
	}
	//注销用户
	function out(){
		session_unset();
		session_destroy();
		go('Index/index');
	}
}
